package com.th.supcom.pds.common.client.model;

import java.util.ArrayList;
import java.util.List;

public class DbErrorMessage
{
    public static class DbErrorModel
    {
        private String m_code;
        private String m_value;

        public String getCode ()
        {
            return m_code;
        }

        public String getValue ()
        {
            return m_value;
        }

        public void setCode (final String code)
        {
            this.m_code = code;
        }

        public void setValue (final String value)
        {
            this.m_value = value;
        }

    }

    private List <DbErrorModel> m_dbErrorModelList;

    public DbErrorMessage ()
    {
        setDbErrors ();
    }

    public String errorMessagesLoad (final String errorMessage)
    {
        for (final DbErrorModel item : m_dbErrorModelList)
        {
            if (errorMessage.contains (item.getCode ()))
            {
                return item.getValue ();
            }
        }
        return errorMessage;
    }

    /**
     * 加载常用错误
     */
    private void setDbErrors ()
    {
        DbErrorModel dbErrorModel = new DbErrorModel ();
        m_dbErrorModelList = new ArrayList <DbErrorModel> ();
        dbErrorModel.setCode ("500");
        dbErrorModel.setValue ("内部服务器错误,请与计算机中心联系！");
        m_dbErrorModelList.add (dbErrorModel);
        dbErrorModel = new DbErrorModel ();
        dbErrorModel.setCode ("ORA-00001");
        dbErrorModel.setValue ("违反唯一性约束,请与计算机中心联系！");
        m_dbErrorModelList.add (dbErrorModel);
        dbErrorModel = new DbErrorModel ();
        dbErrorModel.setCode ("ORA-00018");
        dbErrorModel.setValue ("超出最大会话数,请与计算机中心联系！");
        m_dbErrorModelList.add (dbErrorModel);
        dbErrorModel = new DbErrorModel ();
        dbErrorModel.setCode ("ORA-00051");
        dbErrorModel.setValue ("等待资源超时,请与计算机中心联系！");
        m_dbErrorModelList.add (dbErrorModel);
    }
}
